# This file is part of BlackArch Linux ( https://www.blackarch.org/ ).
# See COPYING for license details.

pkgname=redasm
pkgver=1815.27108ec
pkgrel=1
pkgdesc='Interactive, multiarchitecture disassembler written in C++ using Qt5 as UI Framework.'
arch=('x86_64')
groups=('blackarch' 'blackarch-disassembler' 'blackarch-reversing')
url='https://github.com/REDasmOrg/REDasm'
license=('GPL3')
depends=('qt5-base' 'qt5-webengine')
makedepends=('cmake' 'gcc' 'git' 'qt5-base' 'qt5-webengine')
source=("$pkgname::git+https://github.com/REDasmOrg/REDasm.git")
sha512sums=('SKIP')

pkgver() {
  cd $pkgname

  echo $(git rev-list --count HEAD).$(git rev-parse --short HEAD)
}

prepare() {
  cd $pkgname

  git submodule update --init --recursive
}

build() {
  cd $pkgname

  mkdir -p build
  cd build

  cmake -DCMAKE_BUILD_TYPE=Release ..

  make
}

package() {
  cd $pkgname

  install -dm 755 "$pkgdir/usr/bin/"
  install -dm 755 "$pkgdir/usr/share/$pkgname/"

  install -Dm 644 LICENSE "$pkgdir/usr/share/licenses/$pkgname/LICENSE"

  cd build

  cp -a --no-preserve=ownership LibREDasm.so "$pkgdir/usr/share/$pkgname/"
  cp -a --no-preserve=ownership REDasm "$pkgdir/usr/share/$pkgname/$pkgname"

  git clone https://github.com/REDasmOrg/REDasm-Database.git database

  rm -rf database/.git

  cp -a --no-preserve=ownership database "$pkgdir/usr/share/$pkgname/"

  cat > "$pkgdir/usr/bin/$pkgname" << EOF
#!/bin/sh
cd /usr/share/$pkgname
exec ./$pkgname "\$@"
EOF

  chmod +x "$pkgdir/usr/bin/$pkgname"
}

